package Demo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2022-04-25
 * Time: 下午 16:36
 */
class Sleep<T extends Comparable <T>> {

    public T Max(T[] array) {
        T max = array[0];
        for (int i = 0; i < array.length; i++) {
            if(max.compareTo(array[i]) < 0) {
                max = array[i];
            }
        }
        return max;
    }
}
class Student implements Comparable<Student>{
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }



    @Override
    public int compareTo(Student o) {
        return this.age - o.age;
    }
}
public class TestDemo {
    public static void main(String[] args) {
        Integer[] array = {1,2,3,4,5,6,7};
        Sleep<Integer> sleep = new Sleep<>();
        Integer init = sleep.Max(array);
        System.out.println(init);

        Student[] student = new Student[3];
        student[0] = new Student("zhangsan",20);
        student[1] = new Student("lisi",22);
        student[2] = new Student("wangwu",23);
        Sleep<Student> sleep1 = new Sleep<>();
        Student student2 =sleep1.Max(student);
        System.out.println(student2);

    }
}
